package com.liangwj.springbootdesignpatterns.structureTypePatterns.adapter.demo_1.impl;

import com.liangwj.springbootdesignpatterns.structureTypePatterns.adapter.demo_1.MediaPlayer;

/**
 * <b>Description:</b> 实现了MediaPlayer接口的实体类 <br/>
 * @author Lingwenjun
 * @date 2019/1/23-14:21
 * @version 1.0
 */
public class AudioPlayer implements MediaPlayer {

    private MediaAdapter mediaAdapter;

    @Override
    public void play(String audioType, String filename) {
        //播放MP3的音乐文件的内置支持
        if (("mp3").equalsIgnoreCase(audioType)) {
            System.out.println("Playing mp3 file.name: " + filename);
        }
        //mediaAdapter 提供了其他格式文件的支持
        else if (("vlc").equalsIgnoreCase(audioType) || ("mp4").equalsIgnoreCase(audioType)) {
            mediaAdapter = new MediaAdapter(audioType);
            mediaAdapter.play(audioType, filename);
        } else {
            System.out.println("Invalid media. " + audioType + " format not supported");
        }
    }
}
